package com.bfxy.rabbit.producer.autoconfigure.broker;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.*;

/**
 * 发送消息线程池
 * @author linxin
 */
@Slf4j
public class AsyncBaseQueue {
    // CPU内核数
    private static final int THREAD_SIZE = Runtime.getRuntime().availableProcessors();
    private static final int QUEUE_SIZE = 10000;

    private static ExecutorService senderAsync =
            new ThreadPoolExecutor(THREAD_SIZE,
                    THREAD_SIZE,
                    60L,
                    TimeUnit.SECONDS,
                    new ArrayBlockingQueue<>(QUEUE_SIZE),
                    r -> {
                        Thread thread = new Thread(r);
                        thread.setName("rabbitmq_client_async_sender");
                        return thread;
                    },
                    (r, executor1) -> log.error("async sender is error rejected, runnable: {}, executor: {}", r, executor1)
            );
    public static void submit(Runnable runnable) {
        senderAsync.submit(runnable);
    }

}
